<%@page import="helpers.UrlHelper"%>
<%@page import="models.ConfigModel"%>
<%@page import="java.util.TreeMap"%>
<%@page import="models.CategoryModel"%>
<%@page import="java.util.ArrayList"%>
<%
	ConfigModel siteConfig = (ConfigModel) request.getAttribute("config");
	TreeMap check = (TreeMap) request.getAttribute("check");
	String success = (String) request.getAttribute("success");
	ArrayList<CategoryModel> categories = (ArrayList<CategoryModel>) request.getAttribute("categories");
	CategoryModel category = (CategoryModel) request.getAttribute("category");
	boolean hasChildren = (Boolean) request.getAttribute("hasChildren");
	String form = (String) request.getAttribute("form");
	String image = UrlHelper.getServerUrl(request) + "/blobstore-serve?blob-key=" + siteConfig.getLogo();
%>

<jsp:include page="/layouts/header.jsp">
    <jsp:param name="title" value="<%=siteConfig.getTitle()%>" />
    <jsp:param name="description" value="<%=siteConfig.getMetaDescription()%>" />
    <jsp:param name="keywords" value="<%=siteConfig.getMetaKeywords()%>" />
    <jsp:param name="ogsite_name" value="<%=siteConfig.getSiteName()%>" />
    <jsp:param name="ogtitle" value="<%=siteConfig.getTitle()%>" />
    <jsp:param name="ogurl" value="<%=UrlHelper.getServerUrl(request)%>" />
    <jsp:param name="ogimage" value="<%=image %>" />
    <jsp:param name="ogdescription" value="<%=siteConfig.getMetaDescription()%>" />
</jsp:include>

		<h2 class="title">Link Directory</h2>
		<div class="dir">
			<a href="/submit-link">Submit Link</a> <> 
			<a href="/submit-category">Submit Category</a>
		</div>
		<br />
		<!-- submit form -->
		<div class="submit-form">
			<form action="" method="post">
			<%=success==null?"" : success%>
			<table cellpadding="0" cellspacing="0">
				<thead>
					<tr>
						<td colspan="2"><div class="title-form">Add category</div></td>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td width="30%" class="title">Name</td>
						<td>
							<% if (check.get("name") != null) { %>
								<div class="error"><%=check.get("name")%></div>
							<% } %>
							<input type="text" name="name" value="<%=category.getName() != null ? category.getName() : ""%>">
						</td>
					</tr>
					<tr>
						<td class="title">Parent</td>
						<td>
							<select name="parentId" <%=hasChildren==true? "disabled=\"disabled\"" : "" %> >
								<option value="0"> </option>
								<%
								for (int i = 0; i < categories.size(); i++) {
								%>
								<option value="<%=categories.get(i).getId()%>" <%=category.getParentId() == categories.get(i).getId() ? "selected=\"selected\"" : ""%>>
									|<% for (int j = 2 ; j <= categories.get(i).getLevel(); j++) {%>&nbsp;&nbsp;|<% } %>___
									<%=categories.get(i).getName()%> (<%=categories.get(i).getLevel()%>)
								</option>
								<%
								}
								%>
							</select>
						</td>
					</tr>
					<tr class="dotline">
						<td class="title">Captcha</td>
						<td>
							<% if (check.get("captcha") != null) { %>
								<div class="error"><%=check.get("captcha")%></div>
							<% } %>
							<script>
					        	var RecaptchaOptions = { theme : 'clean' };
					  		</script>
							<script type="text/javascript" src="http://api.recaptcha.net/challenge?k=6LeA0c4SAAAAAMsdjrB49GPol6XImTdJM2U2AHrF"></script>
						</td>
					</tr>
					<tr>
						<td></td>
						<td>
							<button type="submit">Save</button>
						</td>
					</tr>
				</tbody>
			</table>
			</form>
		</div>
		<!-- end submit form -->
		
<jsp:include page="/layouts/footer.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>